package com.zhongkai.tools;

import javax.servlet.ServletContext;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.web.context.support.WebApplicationContextUtils;

public class SpringUtils {
	public static BeanFactory getBeanFactory() {
		String[] Springxml = { "applicationContext.xml",
				"applicationContext-lxj.xml", "applicationContext-actions.xml",
				"applicationContext-common.xml",
				"applicationContext-beans.xml", "applicationContext-util.xml","applicationContext-lw.xml","applicationContext-utils-lw.xml","applicationContext-ywm.xml","applicationContext-fhl.xml" };
		BeanFactory factory = new ClassPathXmlApplicationContext(Springxml);
		return factory;
	}

	public static Object getBean(String BeanName) {
			BeanFactory ctx = getBeanFactory();
		return ctx.getBean(BeanName);
	}

	public static Object getBean(String beanName, ServletContext sc) {
		ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(sc);
		return ctx.getBean(beanName);
	}
	
}
